# Build, package, test, and clean Fatiando

TESTDIR=tmp-test-dir
COVDIR=tmp-cov-dir
PYTEST_ARGS=--doctest-modules -v --pyargs
PYTEST_COV_ARGS=--cov-config=../.coveragerc --cov-report=term-missing

help:
	@echo "Commands:"
	@echo ""
	@echo "    develop       install fatiando in editable mode"
	@echo "    cython        generate C code from Cython files"
	@echo "    test          run the test suite (including doctests)"
	@echo "    pep8          check for PEP8 style compliance"
	@echo "    lint          run static analysis using pylint"
	@echo "    check3        check for compatibility with Python 3"
	@echo "    check         run all code quality checks (pep8, lint, check3)"
	@echo "    coverage      calculate test coverage using Coverage"
	@echo "    clean         clean up build and generated files"
	@echo ""

develop:
	pip install --no-deps -e .

cython:
	python setup.py build_ext --inplace --cython

test:
	# Run a tmp folder to make sure the tests are run on the installed version
	mkdir -p $(TESTDIR)
	cd $(TESTDIR); python -c "import fatiando; fatiando.test(verbose=True)"
	rm -r $(TESTDIR)

coverage:
	# Run a tmp folder to make sure the tests are run on the installed version
	mkdir -p $(COVDIR)
	cd $(COVDIR); pytest $(PYTEST_COV_ARGS) --cov=fatiando $(PYTEST_ARGS) fatiando
	cp $(COVDIR)/.coverage* .
	rm -r $(COVDIR)

pep8:
	flake8 fatiando gallery setup.py

lint:
	pylint fatiando gallery setup.py

check3:
	pylint fatiando gallery setup.py --py3k

check: pep8 check3 lint

clean:
	find . -name "*.so" -exec rm -v {} \;
	find . -name "*.pyc" -exec rm -v {} \;
	rm -rvf build dist MANIFEST fatiando.egg-info __pycache__ .coverage .cache
	# Trash generated by the doctests
	rm -rvf mydata.txt mylogfile.log
	# The stuff fetched by the cookbook recipes
	rm -rvf logo.png cookbook/logo.png
	rm -rvf crust2.tar.gz cookbook/crust2.tar.gz
	rm -rvf bouguer_alps_egm08.grd cookbook/bouguer_alps_egm08.grd
	rm -rvf *.gdf cookbook/*.gdf
	rm -rvf $(TESTDIR) $(COVDIR)
